package com.hx.dc.controllor;

import com.hx.dc.entity.*;
import com.hx.dc.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("employee")
public class EmployeeAction extends BaseAction {

	@Autowired
	private SysParamService sysParamService;

	@Autowired
	private DcEmployeeService dcEmployeeService;

	@Autowired
	private DcCatagotyService dcCatagotyService;

	@Autowired
	private RoleCatagoryService roleCatagoryService;

/*	@RequestMapping(value = "/empmana")
	@ResponseBody
	public Object login(HttpSession session,DcEmployee dcEmployee) {
		List list=dcEmployeeService.selectList(dcEmployee);
		System.out.println(list.get(0));
		return list;
	}*/


	@RequestMapping(value = "/selectPage")
	@ResponseBody
	// easyui提交数据：page:1 rows:15
	public Object selectPage(DcEmployee dcEmployee, Integer page, Integer rows) {
		System.out.println("page:" + page + ",rows:" + rows);
		return this.getPage(dcEmployeeService.selectPage(dcEmployee, page, rows));
	}

	@RequestMapping(value = "/empadd")
	@ResponseBody
	// easyui提交数据：page:1 rows:15
	public Object addEmp(DcEmployee dcEmployee) {
		dcEmployeeService.insert(dcEmployee);
		return null;
	}

	@RequestMapping(value = "/empupdate")
	@ResponseBody
	// easyui提交数据：page:1 rows:15
	public Object updateEmp(DcEmployee dcEmployee) {
		dcEmployeeService.update(dcEmployee);
		return null;
	}
	@RequestMapping(value = "/login")
	public String login(HttpSession session, DcEmployee dcEmployee) {
		System.out.println("---action.sysUser:" + dcEmployee);
		DcEmployee dcEmployee1=dcEmployeeService.login(dcEmployee);
		if (null == dcEmployee1) {
			return "forward:/login.jsp";
		}

		SysParam sysParam=new SysParam();
		sysParam.setSysParamValue(dcEmployee1.getEmployeeStatus());
		sysParam.setSysParamField("dc_role");

		SysParam sysParam1=new SysParam();
		sysParam1=sysParamService.select(sysParam);

		DcRole dcRole=new DcRole();
		dcRole.setRoleName(sysParam1.getSysParamValue());

		List<DcCatagory> catalist=dcCatagotyService.loginSelect(dcRole);

		// 把用户信息和权限信息存到session
		session.setAttribute("catalist", catalist);
		session.setAttribute("sysParam",sysParam1);
		session.setAttribute("dcEmployee",dcEmployee1);
		// 权限信息
		// 略
		return "forward:/WEB-INF/home/home.jsp";
	}

	@RequestMapping(value = "/logout")
	@ResponseBody
	// easyui提交数据：page:1 rows:15
	public String logout(HttpSession session) {
		session.removeAttribute("catalist");
		session.removeAttribute("sysParam");
		session.removeAttribute("dcEmployee");
		return null;
	}

	@RequestMapping(value = "/userupdate")
	@ResponseBody
	// easyui提交数据：page:1 rows:15
	public String userupdate(DcEmployee dcEmployee) {
		System.out.println(dcEmployee);
		dcEmployeeService.update(dcEmployee);
		return null;
	}
}
